package com.ruoyi.web.controller.system;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysAppPrescriptionInfoSort;
import com.ruoyi.system.domain.SysAppPrescriptionSort;
import com.ruoyi.system.service.ISysAppPrescriptionSortService;

/**
 * 方剂分类Controller
 * 
 * @author ruoyi
 * @date 2020-09-04
 */
@Controller
@RequestMapping("/system/sort")
public class SysAppPrescriptionSortController extends BaseController {
	private String prefix = "system/sort";

	@Autowired
	private ISysAppPrescriptionSortService sysAppPrescriptionSortService;

	@RequiresPermissions("system:sort:view")
	@GetMapping()
	public String sort() {
		return prefix + "/sort";
	}

	/**
	 * 查询方剂分类列表
	 */
	@RequiresPermissions("system:sort:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(SysAppPrescriptionSort sysAppPrescriptionSort) {
		startPage();
		List<SysAppPrescriptionSort> list = sysAppPrescriptionSortService
				.selectSysAppPrescriptionSortList(sysAppPrescriptionSort);
		return getDataTable(list);
	}

	/**
	 * 导出方剂分类列表
	 */
	@RequiresPermissions("system:sort:export")
	@Log(title = "方剂分类", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(SysAppPrescriptionSort sysAppPrescriptionSort) {
		List<SysAppPrescriptionSort> list = sysAppPrescriptionSortService
				.selectSysAppPrescriptionSortList(sysAppPrescriptionSort);
		ExcelUtil<SysAppPrescriptionSort> util = new ExcelUtil<SysAppPrescriptionSort>(SysAppPrescriptionSort.class);
		return util.exportExcel(list, "sort");
	}

	/**
	 * 新增方剂分类
	 */
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存方剂分类
	 */
	@RequiresPermissions("system:sort:add")
	@Log(title = "方剂分类", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(SysAppPrescriptionSort sysAppPrescriptionSort) {
		return toAjax(sysAppPrescriptionSortService.insertSysAppPrescriptionSort(sysAppPrescriptionSort));
	}

	/**
	 * 修改方剂分类
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		SysAppPrescriptionSort sysAppPrescriptionSort = sysAppPrescriptionSortService
				.selectSysAppPrescriptionSortById(id);
		mmap.put("sysAppPrescriptionSort", sysAppPrescriptionSort);
		return prefix + "/edit";
	}

	/**
	 * 修改保存方剂分类
	 */
	@RequiresPermissions("system:sort:edit")
	@Log(title = "方剂分类", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(SysAppPrescriptionSort sysAppPrescriptionSort) {
		return toAjax(sysAppPrescriptionSortService.updateSysAppPrescriptionSort(sysAppPrescriptionSort));
	}

	/**
	 * 修改保存方剂分类
	 */
	@RequiresPermissions("system:sort:edit")
	@Log(title = "方剂分类", businessType = BusinessType.UPDATE)
	@PostMapping("/edit1")
	@ResponseBody
	public AjaxResult editSave1(SysAppPrescriptionSort sysAppPrescriptionSort) {
		return toAjax(1);
	}
	/**
	 * 删除方剂分类
	 */
	@RequiresPermissions("system:sort:remove")
	@Log(title = "方剂分类", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(sysAppPrescriptionSortService.deleteSysAppPrescriptionSortByIds(ids));
	}

	/**
	 * 查询字典详细
	 */
	@RequiresPermissions("system:sort:list")
	@GetMapping("/detail/{sortId}")
	public String detail(@PathVariable("sortId") Long sortId, ModelMap mmap) {
		mmap.put("sort", sysAppPrescriptionSortService.selectSysAppPrescriptionSortById(sortId));
		return "system/info/info";
	}
	
	@GetMapping("/goInfo/{id}")
	public String goInfo(@PathVariable("id") Long id, ModelMap mmap) {
		SysAppPrescriptionSort sysAppPrescriptionSort = sysAppPrescriptionSortService.selectSysAppPrescriptionSortById(id);
		mmap.put("sysAppPrescriptionSort", sysAppPrescriptionSort);
		return prefix + "/addInfo";
	}
}
